/**
 * 用于记录坐席所有话务操作日志
 * Created by lixia on 2016/11/1.
 */
var AgentLog = function(option){

    var lastId = "";

    var config = {
        userId: "",
        userName: "",
        agentId: "",
        tenantsId: "",
        agentDn: "",
        proxyUrl: ""
    };

    setOption(option);

    function setOption(option){
        option = option || {};
        if (option.hasOwnProperty('userId')) {
            config.userId = option.userId + '';
        }
        if (option.hasOwnProperty('userName')) {
            config.userName = option.userName + '';
        }
        if (option.hasOwnProperty('agentId')) {
            config.agentId = option.agentId + '';
        }
        if (option.hasOwnProperty('tenantsId')) {
            config.tenantsId = option.tenantsId + '';
        }
        if (option.hasOwnProperty('agentDn')) {
            config.agentDn = option.agentDn + '';
        }
        if (option.hasOwnProperty('proxyUrl')) {
            config.proxyUrl = option.proxyUrl + '';
        }
    }

    function sendMessage(type, otherDn, customerId, callDirection){
        if(!otherDn){
            otherDn = "";
        }
        if(!customerId){
            customerId = "-1";
        }
        if(!callDirection){
            callDirection = "0";
        }
        var data;
        var id = Math.uuid();
        switch (type){
            case LOGIN :{
                data = {
                    id: id,
                    callDirection: callDirection,
                    customerId: customerId,
                    userId: config.userId,
                    userName: config.userName,
                    agentId: config.agentId,
                    tenantsId: config.tenantsId,
                    agentDn: config.agentDn,
                    otherDn: otherDn,
                    actionType : LOGIN,
                    remarks : LOGIN_INFO
                };
                break;
            }
            case READY :{
                data = {
                    id: id,
                    lastId: lastId,
                    callDirection: callDirection,
                    customerId: customerId,
                    userId: config.userId,
                    userName: config.userName,
                    agentId: config.agentId,
                    tenantsId: config.tenantsId,
                    agentDn: config.agentDn,
                    otherDn: otherDn,
                    actionType : READY,
                    remarks : READY_INFO
                };
                break;
            }
            case BUSY :{
                data = {
                    id: id,
                    lastId: lastId,
                    callDirection: callDirection,
                    customerId: customerId,
                    userId: config.userId,
                    userName: config.userName,
                    agentId: config.agentId,
                    tenantsId: config.tenantsId,
                    agentDn: config.agentDn,
                    otherDn: otherDn,
                    actionType : BUSY,
                    remarks : BUSY_INFO
                };
                break;
            }
            case REST :{
                data = {
                    id: id,
                    lastId: lastId,
                    callDirection: callDirection,
                    customerId: customerId,
                    userId: config.userId,
                    userName: config.userName,
                    agentId: config.agentId,
                    tenantsId: config.tenantsId,
                    agentDn: config.agentDn,
                    otherDn: otherDn,
                    actionType : REST,
                    remarks : REST_INFO
                };
                break;
            }
            case TRAIN :{
                data = {
                    id: id,
                    lastId: lastId,
                    callDirection: callDirection,
                    customerId: customerId,
                    userId: config.userId,
                    userName: config.userName,
                    agentId: config.agentId,
                    tenantsId: config.tenantsId,
                    agentDn: config.agentDn,
                    otherDn: otherDn,
                    actionType : TRAIN,
                    remarks : TRAIN_INFO
                };
                break;
            }
            case MEAL :{
                data = {
                    id: id,
                    lastId: lastId,
                    callDirection: callDirection,
                    customerId: customerId,
                    userId: config.userId,
                    userName: config.userName,
                    agentId: config.agentId,
                    tenantsId: config.tenantsId,
                    agentDn: config.agentDn,
                    otherDn: otherDn,
                    actionType : MEAL,
                    remarks : MEAL_INFO
                };
                break;
            }
            case ANSWER :{
                data = {
                    id: id,
                    lastId: lastId,
                    callDirection: callDirection,
                    customerId: customerId,
                    userId: config.userId,
                    userName: config.userName,
                    agentId: config.agentId,
                    tenantsId: config.tenantsId,
                    agentDn: config.agentDn,
                    otherDn: otherDn,
                    actionType : ANSWER,
                    remarks : ANSWER_INFO
                };
                break;
            }
            case CALL :{
                data = {
                    id: id,
                    lastId: lastId,
                    callDirection: callDirection,
                    customerId: customerId,
                    userId: config.userId,
                    userName: config.userName,
                    agentId: config.agentId,
                    tenantsId: config.tenantsId,
                    agentDn: config.agentDn,
                    otherDn: otherDn,
                    actionType : CALL,
                    remarks : CALL_INFO
                };
                break;
            }
            case HANG_UP :{
                data = {
                    id: id,
                    lastId: lastId,
                    callDirection: callDirection,
                    customerId: customerId,
                    userId: config.userId,
                    userName: config.userName,
                    agentId: config.agentId,
                    tenantsId: config.tenantsId,
                    agentDn: config.agentDn,
                    otherDn: otherDn,
                    actionType : HANG_UP,
                    remarks : HANG_UP_INFO
                };
                break;
            }
            case TRANSFER :{
                data = {
                    id: id,
                    lastId: lastId,
                    callDirection: callDirection,
                    customerId: customerId,
                    userId: config.userId,
                    userName: config.userName,
                    agentId: config.agentId,
                    tenantsId: config.tenantsId,
                    agentDn: config.agentDn,
                    otherDn: otherDn,
                    actionType : TRANSFER,
                    remarks : TRANSFER_INFO
                };
                break;
            }
            case TRANSFER_SUCCESS :{
                data = {
                    id: id,
                    lastId: lastId,
                    callDirection: callDirection,
                    customerId: customerId,
                    userId: config.userId,
                    userName: config.userName,
                    agentId: config.agentId,
                    tenantsId: config.tenantsId,
                    agentDn: config.agentDn,
                    otherDn: otherDn,
                    actionType : TRANSFER_SUCCESS,
                    remarks : TRANSFER_SUCCESS_INFO
                };
                break;
            }
            case TRANSFER_CANCEL :{
                data = {
                    id: id,
                    lastId: lastId,
                    callDirection: callDirection,
                    customerId: customerId,
                    userId: config.userId,
                    userName: config.userName,
                    agentId: config.agentId,
                    tenantsId: config.tenantsId,
                    agentDn: config.agentDn,
                    otherDn: otherDn,
                    actionType : TRANSFER_CANCEL,
                    remarks : TRANSFER_CANCEL_INFO
                };
                break;
            }
            case TRANSFER_FIX :{
                data = {
                    id: id,
                    lastId: lastId,
                    callDirection: callDirection,
                    customerId: customerId,
                    userId: config.userId,
                    userName: config.userName,
                    agentId: config.agentId,
                    tenantsId: config.tenantsId,
                    agentDn: config.agentDn,
                    otherDn: otherDn,
                    actionType : TRANSFER_FIX,
                    remarks : TRANSFER_FIX_INFO
                };
                break;
            }
            case TRANSFER_GROUP :{
                data = {
                    id: id,
                    lastId: lastId,
                    callDirection: callDirection,
                    customerId: customerId,
                    userId: config.userId,
                    userName: config.userName,
                    agentId: config.agentId,
                    tenantsId: config.tenantsId,
                    agentDn: config.agentDn,
                    otherDn: otherDn,
                    actionType : TRANSFER_GROUP,
                    remarks : TRANSFER_GROUP_INFO
                };
                break;
            }
            case CONFERENCE :{
                data = {
                    id: id,
                    lastId: lastId,
                    callDirection: callDirection,
                    customerId: customerId,
                    userId: config.userId,
                    userName: config.userName,
                    agentId: config.agentId,
                    tenantsId: config.tenantsId,
                    agentDn: config.agentDn,
                    otherDn: otherDn,
                    actionType : CONFERENCE,
                    remarks : CONFERENCE_INFO
                };
                break;
            }
            case CONFERENCE_CANCEL :{
                data = {
                    id: id,
                    lastId: lastId,
                    callDirection: callDirection,
                    customerId: customerId,
                    userId: config.userId,
                    userName: config.userName,
                    agentId: config.agentId,
                    tenantsId: config.tenantsId,
                    agentDn: config.agentDn,
                    otherDn: otherDn,
                    actionType : CONFERENCE_CANCEL,
                    remarks : CONFERENCE_CANCEL_INFO
                };
                break;
            }
            case CONFERENCE_FIX :{
                data = {
                    id: id,
                    lastId: lastId,
                    callDirection: callDirection,
                    customerId: customerId,
                    userId: config.userId,
                    userName: config.userName,
                    agentId: config.agentId,
                    tenantsId: config.tenantsId,
                    agentDn: config.agentDn,
                    otherDn: otherDn,
                    actionType : CONFERENCE_FIX,
                    remarks : CONFERENCE_FIX_INFO
                };
                break;
            }
            case LOGOUT :{
                data = {
                    id: id,
                    lastId: lastId,
                    callDirection: callDirection,
                    customerId: customerId,
                    userId: config.userId,
                    userName: config.userName,
                    agentId: config.agentId,
                    tenantsId: config.tenantsId,
                    agentDn: config.agentDn,
                    otherDn: otherDn,
                    actionType : LOGOUT,
                    remarks : LOGOUT_INFO
                };
                break;
            }
            case RINGING :{
                data = {
                    id: id,
                    lastId: lastId,
                    callDirection: callDirection,
                    customerId: customerId,
                    userId: config.userId,
                    userName: config.userName,
                    agentId: config.agentId,
                    tenantsId: config.tenantsId,
                    agentDn: config.agentDn,
                    otherDn: otherDn,
                    actionType : RINGING,
                    remarks : RINGING_INFO
                };
                break;
            }
            case DIALING :{
                data = {
                    id: id,
                    lastId: lastId,
                    callDirection: callDirection,
                    customerId: customerId,
                    userId: config.userId,
                    userName: config.userName,
                    agentId: config.agentId,
                    tenantsId: config.tenantsId,
                    agentDn: config.agentDn,
                    otherDn: otherDn,
                    actionType : DIALING,
                    remarks : DIALING_INFO
                };
                break;
            }
            case ESTABLISHED :{
                data = {
                    id: id,
                    lastId: lastId,
                    callDirection: callDirection,
                    customerId: customerId,
                    userId: config.userId,
                    userName: config.userName,
                    agentId: config.agentId,
                    tenantsId: config.tenantsId,
                    agentDn: config.agentDn,
                    otherDn: otherDn,
                    actionType : ESTABLISHED,
                    remarks : ESTABLISHED_INFO
                };
                break;
            }
            case RELEASED :{
                data = {
                    id: id,
                    lastId: lastId,
                    callDirection: callDirection,
                    customerId: customerId,
                    userId: config.userId,
                    userName: config.userName,
                    agentId: config.agentId,
                    tenantsId: config.tenantsId,
                    agentDn: config.agentDn,
                    otherDn: otherDn,
                    actionType : RELEASED,
                    remarks : RELEASED_INFO
                };
                break;
            }
            case HOLD :{
                data = {
                    id: id,
                    lastId: lastId,
                    callDirection: callDirection,
                    customerId: customerId,
                    userId: config.userId,
                    userName: config.userName,
                    agentId: config.agentId,
                    tenantsId: config.tenantsId,
                    agentDn: config.agentDn,
                    otherDn: otherDn,
                    actionType : HOLD,
                    remarks : HOLD_INFO
                };
                break;
            }
            case RECOVERY :{
                data = {
                    id: id,
                    lastId: lastId,
                    callDirection: callDirection,
                    customerId: customerId,
                    userId: config.userId,
                    userName: config.userName,
                    agentId: config.agentId,
                    tenantsId: config.tenantsId,
                    agentDn: config.agentDn,
                    otherDn: otherDn,
                    actionType : RECOVERY,
                    remarks : RECOVERY_INFO
                };
                break;
            }
            case AFTER_CALL_WORK :{
                data = {
                    id: id,
                    lastId: lastId,
                    callDirection: callDirection,
                    customerId: customerId,
                    userId: config.userId,
                    userName: config.userName,
                    agentId: config.agentId,
                    tenantsId: config.tenantsId,
                    agentDn: config.agentDn,
                    otherDn: otherDn,
                    actionType : AFTER_CALL_WORK,
                    remarks : AFTER_CALL_WORK_INFO
                };
                break;
            }
        }

        lastId = id;

        if(data){
            $.post(config.proxyUrl, data);
        }
    }

    this.sendMessage = function(type, otherDn, customerId, callDirection){
        return sendMessage(type, otherDn, customerId, callDirection);
    }

    var LOGIN = 1001;
    var LOGIN_INFO = "签入";
    this.LOGIN = LOGIN;

    var READY = 1002;
    var READY_INFO = "就绪";
    this.READY = READY;

    var BUSY = 1003;
    var BUSY_INFO = "置忙";
    this.BUSY = BUSY;

    var REST = 1004;
    var REST_INFO = "小休";
    this.REST = REST;

    var TRAIN = 1005;
    var TRAIN_INFO = "培训";
    this.TRAIN = TRAIN;

    var MEAL = 1006;
    var MEAL_INFO = "就餐";
    this.MEAL = MEAL;

    var ANSWER = 1007;
    var ANSWER_INFO = "接听";
    this.ANSWER = ANSWER;

    var CALL = 1008;
    var CALL_INFO = "外呼";
    this.CALL = CALL;

    var HANG_UP = 1009;
    var HANG_UP_INFO = "挂断";
    this.HANG_UP = HANG_UP;

    var TRANSFER = 1010;
    var TRANSFER_INFO = "转移咨询";
    this.TRANSFER = TRANSFER;

    var TRANSFER_SUCCESS = 10111;
    var TRANSFER_SUCCESS_INFO = "转移成功";
    this.TRANSFER_SUCCESS = TRANSFER_SUCCESS;

    var TRANSFER_CANCEL = 1011;
    var TRANSFER_CANCEL_INFO = "取消转移";
    this.TRANSFER_CANCEL = TRANSFER_CANCEL;

    var TRANSFER_FIX = 1012;
    var TRANSFER_FIX_INFO = "确定转移";
    this.TRANSFER_FIX = TRANSFER_FIX;

    var TRANSFER_GROUP = 1013;
    var TRANSFER_GROUP_INFO = "转移组";
    this.TRANSFER_GROUP = TRANSFER_GROUP;

    var CONFERENCE = 1014;
    var CONFERENCE_INFO = "会议咨询";
    this.CONFERENCE = CONFERENCE;

    var CONFERENCE_CANCEL = 1015;
    var CONFERENCE_CANCEL_INFO = "取消会议";
    this.CONFERENCE_CANCEL = CONFERENCE_CANCEL;

    var CONFERENCE_FIX = 1016;
    var CONFERENCE_FIX_INFO = "确认会议";
    this.CONFERENCE_FIX = CONFERENCE_FIX;

    var LOGOUT = 1017;
    var LOGOUT_INFO = "签出";
    this.LOGOUT = LOGOUT;

    var RINGING = 1018;
    var RINGING_INFO = "来电响铃";
    this.RINGING = RINGING;

    var DIALING = 1019;
    var DIALING_INFO = "外呼响铃";
    this.DIALING = DIALING;

    var ESTABLISHED = 1020;
    var ESTABLISHED_INFO = "电话接通";
    this.ESTABLISHED = ESTABLISHED;

    var RELEASED = 1021;
    var RELEASED_INFO = "通话结束";
    this.RELEASED = RELEASED;

    var HOLD = 1022;
    var HOLD_INFO = "保持";
    this.HOLD = HOLD;

    var RECOVERY = 1023;
    var RECOVERY_INFO = "恢复";
    this.RECOVERY = RECOVERY;

    var AFTER_CALL_WORK = 1024;
    var AFTER_CALL_WORK_INFO = "话后处理";
    this.AFTER_CALL_WORK = AFTER_CALL_WORK;

}